package com.visionblue.business.ship.modbus

import android.util.Log
import com.visionblue.business.ship.modbus.utilities.floatInverse
import com.visionblue.business.ship.model.bean.local.OilFlowInfo

/**
 * @author: xlh
 * @date: 2020-06-02 2:04 PM
 * @desc:
 */
class OilInfoParser {

//    private val accumulationUnitParser: IOilFlowAccumulationUnitParser =
//        BOilFlowAccumulationUnitParserImpllFlowAccumulationUnitParserImpl()

    fun parse(results: IntArray): OilFlowInfo {
        val oilFlowInfo = OilFlowInfo()
        // 数组中的一个元素代表了一个地址空间对应的值   也就是2字节

        // 瞬时流量
//        oilFlowInfo.instantFlowRate = floatInverse(results, 0, 1)
//
//        // 瞬时流速
//        oilFlowInfo.instantFlowSpeed = floatInverse(results, 2, 3)
//
//        // 流量百分比
//        oilFlowInfo.flowRatePercent = floatInverse(results, 4, 5)
//
//        // 流体电导比
//        oilFlowInfo.flowElectronicRate = floatInverse(results, 6, 7)
//
//        // 正向累计整数部分
//        oilFlowInfo.positiveAccumulationIntPart = longInverse(results, 8, 9)
//
//        // 正向累计小数部分
//        oilFlowInfo.positiveAccumulationDecimalPart = floatInverse(results, 10, 11)

//        oilFlowInfo.positiveAccumulationVal =
//            oilFlowInfo.positiveAccumulationIntPart + oilFlowInfo.positiveAccumulationDecimalPart

        // 反向累计整数部分
//        oilFlowInfo.negativeAccumulationIntPart =
//            longInverse(results, 12, 13)
//
//        // 反向累计小数部分
//        oilFlowInfo.negativeAccumulationDecimalPart =
//            floatInverse(results, 14, 15)
//
//        // 瞬时流量单位
//        oilFlowInfo.instantFlowUnit = InstantFlowUnit.fromKey(results[16])
//
//        // 累计总量单位
//        oilFlowInfo.accumulationFlowUnit =
//            accumulationUnitParser.getAccumulationFlowUnit(results[17])
//
//        // 上限报警
//        oilFlowInfo.isUpperLimitWarning = results[18] and 1 == 1
//
//        // 下线报警
//        oilFlowInfo.isLowerLimitWarning = results[19] and 1 == 1
//
//        // 空管报警
//        oilFlowInfo.isEmptyWarning = results[20] and 1 == 1
//
//        // 系统报警
//        oilFlowInfo.isSystemWarning = results[21] and 1 == 1

        // 瞬时流量
        oilFlowInfo.instantFlowRate = floatInverse(results, 0, 1)
        // 2, 3  密度
        // 4, 5  差压/频率/体积
        oilFlowInfo.positiveAccumulationVal = floatInverse(results, 6, 7)

        Log.e("流量计-解析结果油：",oilFlowInfo.toString()+"oil")
        return oilFlowInfo
    }
}